package cn.edu.sdu.sol.material_management_system.config;

import cn.edu.sdu.sol.intake_system.security.intercepter.SuperAdminInterceptor;
import cn.edu.sdu.sol.intake_system.security.intercepter.TokenInterceptor;
import cn.edu.sdu.sol.intake_system.security.intercepter.ZAdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Autowired
    private ZAdminInterceptor zAdminInterceptor;

    @Autowired
    private SuperAdminInterceptor superAdminInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/api/**") // 添加需要拦截的路径规则
                .excludePathPatterns("/api/auth/login")
                .excludePathPatterns("/api/auth/hello"); // 排除不需要拦截的路径
        registry.addInterceptor(zAdminInterceptor)
                .addPathPatterns("/api/admin/**")
                .addPathPatterns("api/superAdmin/getAdminList");
        registry.addInterceptor(superAdminInterceptor)
                .addPathPatterns("/api/superAdmin/**")
                .excludePathPatterns("/api/superAdmin/getAdminList");
    }

}

